package com.OtherExercises;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayList外卖系统案例 {
    public static void main(String[] args) {
        FoodManagement fm = new FoodManagement();
        fm.start();
    }
}

/**
 * JavaBean
 */
class Food {
    private String name;
    private double originalPrice;
    private double specialPrice;
    private String information;

    /**
     * 重写toString函数
     */
    @Override
    public String toString() {
        return "Food{" +
                "name='" + name + '\'' +
                ", originalPrice=" + originalPrice +
                ", specialPrice=" + specialPrice +
                ", information='" + information + '\'' +
                '}';
    }

    /**
     * 无参构造
     */
    public Food() {
    }

    /**
     * 满参构造
     *
     * @param name
     * @param originalPrice
     * @param specialPrice
     * @param information
     */
    public Food(String name, double originalPrice, double specialPrice, String information) {
        this.name = name;
        this.originalPrice = originalPrice;
        this.specialPrice = specialPrice;
        this.information = information;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getOriginalPrice() {
        return originalPrice;
    }

    public void setOriginalPrice(double originalPrice) {
        this.originalPrice = originalPrice;
    }

    public double getSpecialPrice() {
        return specialPrice;
    }

    public void setSpecialPrice(double specialPrice) {
        this.specialPrice = specialPrice;
    }

    public String getInformation() {
        return information;
    }

    public void setInformation(String information) {
        this.information = information;
    }
}

class FoodManagement {
    private ArrayList<Food> foods = new ArrayList<>();
    private Scanner sc = new Scanner(System.in);

    /**
     * 菜品上架
     */
    public void add() {
        System.out.println("==菜品上架==");
        Food food = new Food();
        System.out.println("请输入菜品的名称:");
        food.setName(sc.next());
        System.out.println("请输入菜品的原价:");
        food.setOriginalPrice(sc.nextDouble());
        System.out.println("请输入菜品的优惠价:");
        food.setSpecialPrice(sc.nextDouble());
        System.out.println("请输入菜品的其他信息:");
        food.setInformation(sc.next());

        foods.add(food);
        System.out.println("恭喜您,上架成功~");
        System.out.println("--------------");

    }

    /**
     * 菜品浏览
     */
    public void printAllFoods() {
        System.out.println("==菜品信息如下==");
        for (int i = 0; i < foods.size(); i++) {
            System.out.println("名称:" + foods.get(i).getName());
            System.out.println("原价:" + foods.get(i).getOriginalPrice());
            System.out.println("优惠价:" + foods.get(i).getSpecialPrice());
            System.out.println("其他信息:" + foods.get(i).getInformation());
            System.out.println("--------------");
        }
    }

    /**
     * 启动菜单界面
     */
    public void start() {
        System.out.println("====欢迎进入商家后台管理系统====");

        loop:
        while (true) {
            System.out.println("1.上架菜品(add)");
            System.out.println("2.浏览菜品(query)");
            System.out.println("3.退出系统(exit)");
            System.out.println("请您选择操作命令:");
            String command = sc.next();
            switch (command) {
                case "add":
                    add();
                    break;
                case "query":
                    printAllFoods();
                    break;
                case "exit":
                    break loop;
                default:
                    System.out.println("您输入的操作命令有误!");
            }
        }
    }


}


